package com.mobilebsc.datatype;

import org.json.JSONException;
import org.json.JSONObject;

public class SignalAssociation {

	private int id;
	private WeakSignal weakSignal;
	private KPI kpi;
	private double influence;

	/**
	 * Constructor for empty signal associations
	 */
	public SignalAssociation() {
		this.id = -1;
		this.weakSignal = null;
		this.kpi = null;
		this.influence = -1.0;
	}

	public SignalAssociation(int signalAssociationId, WeakSignal weakSignal,
			KPI kpi, double influence) {
		super();
		this.id = signalAssociationId;
		this.weakSignal = weakSignal;
		this.kpi = kpi;
		this.influence = influence;
	}

	/**
	 * Use for instancing a new SignalAssociation from UI: id is set by database
	 * 
	 * @param weakSignal
	 * @param kpi
	 * @param influence
	 */
	public SignalAssociation(WeakSignal weakSignal, KPI kpi, double influence) {
		super();
		this.id = 0;
		this.weakSignal = weakSignal;
		this.kpi = kpi;
		this.influence = influence;
	}

	public int getSignalAssociationId() {
		return id;
	}

	public WeakSignal getWeakSignal() {
		return weakSignal;
	}

	public KPI getKpi() {
		return kpi;
	}

	public double getInfluence() {
		return influence;
	}

	public void setSignalAssociationId(int signalAssociationId) {
		this.id = signalAssociationId;
	}

	public void setWeakSignal(WeakSignal weakSignal) {
		this.weakSignal = weakSignal;
	}

	public void setKpi(KPI kpi) {
		this.kpi = kpi;
	}

	public void setInfluence(double influence) {
		this.influence = influence;
	}

	/**
	 * Returns signal association as a JSONObject
	 * 
	 * @return
	 * @throws JSONException
	 */
	public JSONObject getJSON() throws JSONException {
		JSONObject json = new JSONObject();

		JSONObject kpi = getKpi().getJSON();
		JSONObject weaksignal = getWeakSignal().getJSON();

		json.put("influence", getInfluence());
		json.put("kpi", kpi);
		json.put("weaksignal", weaksignal);
		json.put("signalassociationmapid", getSignalAssociationId());

		return json;
	}
}